﻿// See https://aka.ms/new-console-template for more information
using System.Runtime.InteropServices;


    public class Musicplay
    {
        [DllImport("winmm.dll", CharSet = CharSet.Unicode)]
        private static extern uint MciSendString(string lpstrCommand, string? lpstrReturnString, uint uReturnLength, uint hWndCallback);

        public static void PlayNmusinc(string path)
        {
            var i = MciSendString(@"close temp_alias", null, 0, 0);
            if (i > 0)
            {
                var j = MciSendString(@"open """ + path + @""" alias temp_alias", null, 0, 0);
                if (j > 0)
                {
                    _ = MciSendString("play temp_alias repeat", null, 0, 0);


                }

            }
        }

        /// <summary>
        /// 播放音乐文件(重复)
        /// </summary>
        /// <param name="p_FileName">音乐文件名称</param>
        public static void PlayMusic_Repeat(string p_FileName)
        {
            try
            {
                _ = MciSendString(@"close temp_music", " ", 0, 0);
                _ = MciSendString(@"open " + p_FileName + " alias temp_music", " ", 0, 0);
                _ = MciSendString(@"play temp_music repeat", " ", 0, 0);
            }
            catch
            { }
        }

        /// <summary>
        /// 播放音乐文件
        /// </summary>
        /// <param name="p_FileName">音乐文件名称</param>
        public static void PlayMusic(string p_FileName)
        {
            try
            {
                _ = MciSendString(@"close temp_music", " ", 0, 0);
                //mciSendString(@"open " + p_FileName + " alias temp_music", " ", 0, 0);
                _ = MciSendString(@"open """ + p_FileName + @""" alias temp_music", null, 0, 0);
                _ = MciSendString(@"play temp_music", " ", 0, 0);
            }
            catch
            { }
        }

        /// <summary>
        /// 停止当前音乐播放
        /// </summary>
        /// <param name="p_FileName">音乐文件名称</param>
        public static void StopMusic(string p_FileName)
        {
            try
            {
                _ = MciSendString(@"close " + p_FileName, " ", 0, 0);
            }
            catch { }
        }

    }

    public class WavePlayer
    {

    }